package com.xcf.interceptor;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author WongBin
 * @date 2017/11/10.
 */
@Aspect
@Component
public class LogAop {
    private static Logger logger = LoggerFactory.getLogger(LogAop.class);

    @Pointcut("execution(* com.xcf.controller..*.*(..))")
    private void anyMethod(){}

    @Around("anyMethod()")
    public Object doBasicProfiling(ProceedingJoinPoint pjp){
        Object object;
        logger.info("aop-args:"+pjp.getArgs().toString());
        try {
            object = pjp.proceed();
        } catch (Throwable ex) {
            logger.error("callServiceError:",ex);
            Map<String,Object> binfo = new HashMap<String,Object>();
            binfo.put("code", "ERROR");
            binfo.put("message", "系统异常");
            return binfo;
        }
        return object;
    }

}
